package com.cn.admin.controller;


import com.cn.admin.entity.Dept;
import com.cn.admin.entity.DeptQuery;
import com.cn.admin.service.DeptService;
import com.cn.admin.vo.ResponseObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class DeptController {


    @Autowired
    private DeptService deptService;

    @PostMapping("/dept/list")
    public Object list(){

        List<Dept> depts = deptService.selectByExample(new DeptQuery());

        return ResponseObject.success(depts);
    }

    @PostMapping("/dept/get")
    public Object get(Long id){

        Dept dept = deptService.selectByPrimaryKey(id);

        return ResponseObject.success(dept);
    }

    @PostMapping("/dept/insert")
    public Object get(Dept dept){

        int i = deptService.insertSelective(dept);

        return ResponseObject.success(i);
    }


    @PostMapping("/dept/edit")
    public Object edit(Dept dept){

        int i = deptService.updateByPrimaryKeySelective(dept);

        return ResponseObject.success(i);
    }
}
